<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	     <title>路由预设</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<link rel="stylesheet" type="text/css" href="<%=basePath%>CSS/layout.css" />
  </head>
  
  <body>
<div id="wrapper">
    <!--头部菜单开始-->
    <jsp:include page="/common/head.jsp"></jsp:include>
    <!--头部菜单结束-->
	<div id="BreadCrumb">我的位置：基本资料管理 &gt; 路由预设管理</div>
	<div id="REC_content">
	    <fieldset id="BasicInfo" class="mainField">
		    <legend><span class="title">路由预设管理</span></legend>
			<div class="innerCon">
			    <div class="mainSearchBox">
			       <table width="100%" cellpadding="0" cellspacing="0" border="0" class="editTab">
			        <form:form name="settingForm" action="routeSetting.do" method="post" modelAttribute="vo">
					<tr height="35">
						<td width="80" class="title"><fmt:message key="product.styleno"/></td>
						<td align="left" width="80"><form:input path="proStyleNo" id="proStyleNo" size="8"/></td>
						<td width="80" class="title" align="left"><fmt:message key="product.routeType"/></td>
						<td align="left">
						   <form:select path="routeType" id="routeType">
						     <c:forEach var="routeType" items="${routeTypes}">
						       <form:option value="${routeType}">${routeType}</form:option>
						     </c:forEach>
						   </form:select>
						</td>
						
					</tr>
					<tr height="35">
					    <td width="80" class="title"><fmt:message key="routeSetting.comment"/></td>
						<td align="left"><form:input path="comment" id="comment"/></td>
						<td width="190" align="left">
						  <input type="button" name="searchButton" class="newSearchButton" value="新增" onclick="create()"/> 
						  <input type="submit" name="searchButton" class="newSearchButton" value="查询" /> 
						</td>
					</tr>
					<form:hidden path="curPage" id="curPage"/>
					</form:form>
					<tr id="moresearchCon">
						<td class="title" height="30">文件导入</td>
						<td colspan="4">
						  <form action="importRouteSetting.do" method="post" enctype="multipart/form-data">
						  <input type="file" name="excelFile" id="file1" /><img id="loading" src="img/loading.gif" style="display:none" />
				          <input type="submit" class="newSearchButton" value="导入" />
				          <a href="<%=basePath%>OrderExcel/routeSetting.xls">模板下载</a>
				          </form>
						</td>
					</tr>
				</table>
				
			    
			    </div>
			    <!-- begin tab -->
			    <div class="topControl clearfix">
				    <div id="JobsMgrTabCon" class="itemTabCon">
					    <ul id="JobsMgrTabs" class="itemTabs">
							<li id="dueTab" class="focus"><a href="<%=basePath%>routeSetting.do"  onfocus="this.blur()">路由预设管理</a></li>
							<li id="dueTab" class="blur"><a href="<%=basePath%>wip.do">产品分配管理</a></li>
							<li id="dueTab" class="blur"><a href="<%=basePath%>orderWip.do">在制产品管理</a></li>
					    </ul>
				    </div>
			    </div>
			    
			    
			    <!-- end tab -->
				<div id="mainListCon">
				    <div class="infoCon">
					  <div class="info">
							  总共${page.rowCnt}条记录, 每页显示${page.pageSize}, 共${page.pageCnt}页
					  </div>
					</div>
				    <div class="tableCon">
							    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="listTab" id="tableData">
							        <tr class="tabHead">
								        <td class="blankTd"></td>
								        <td><fmt:message key="routeSetting.wdId"/></td>
									    <td><fmt:message key="routeSetting.routeType"/></td>
										<td><fmt:message key="routeSetting.proStyleNo"/></td>
										<td><fmt:message key="routeSetting.comment"/></td>
										<td><fmt:message key="routeSetting.createTime"/></td>
										<td></td>
									</tr>
									
									<c:forEach var="routeSetting" items="${page.pageList}" varStatus="idx">
									<tr class="${idx.index%2==0?'list1':'list2'}" id="${routeSetting.wdId}">
									    <td class='tdCheckbox'></td>
								     	<td>${routeSetting.wdId}</td>
									    <td>
									       <select id="RouteType${routeSetting.wdId}" onchange="this.style.backgroundColor='#E5F0FF';">
									           <c:forEach var="routeType" items="${routeTypes}">
						                            <option value="${routeType}" <c:if test="${routeType eq routeSetting.routeType}">selected</c:if>>${routeType}</option>
						                       </c:forEach>
									       </select>
									    </td>
									    <td><input type="text" onchange="this.style.backgroundColor='#E5F0FF';" id="ProStyleNo${routeSetting.wdId}" value="${routeSetting.proStyleNo}" /></td>
										<td><input type="text" onchange="this.style.backgroundColor='#E5F0FF';" id="Comment${routeSetting.wdId}" value="${routeSetting.comment}" /></td>
										<td>
										  <fmt:formatDate value="${routeSetting.createTime}"/>
									    </td>
										<td>
										  <input name="" class="newSearchButton" type="button" class="btn" onclick="update(${routeSetting.wdId})" value="修改" /> 
										  <input name="" class="newSearchButton" type="button" class="btn" value="删除" onclick="del(${routeSetting.wdId})"/>
									    </td>
									</tr>
									</c:forEach>
								</table> 
					  </div>
					  <div class="turnpageCon clearfix">
							<div class="turnpage">
							 ${page.simpleBar}
							</div>
						</div>
				</div>
			</div>
		</fieldset>
	</div>
	<jsp:include page="/common/foot.jsp"></jsp:include>
</div>
    <script type="text/javascript" src="<%=basePath%>js/jquery.js"language="javascript"></script>
    <script type="text/javascript" src="<%=basePath%>js/ftyUtils.js"language="javascript"></script>
	<script src='<%=basePath%>dwr/interface/routeService.js'></script>
    <script src="<%=basePath%>dwr/engine.js"></script>
    <script type="text/javascript" language="javascript">
     function del(routeId){
               if(confirm("确定要删除编号为:"+routeId+"的路由设置吗?")){
                routeService.delRouteSetting(routeId,function(){
                   $("#"+routeId).remove();
                   alert("删除成功!");
                   window.location.reload();
                });
               }else return;
             }
     function create(){
               var routeType = $.trim($("#routeType").val());
               var styleNo = $.trim($("#proStyleNo").val());
               var comment = $.trim($("#commnet").val());
               
               if(routeType==""||styleNo==""){
                 alert("路由设置或款号不能为空!");
                 return;
               }else{
                 routeService.regRouteSetting({routeType:routeType,proStyleNo:styleNo,comment:comment},function(){
                     alert("新增成功!");
                     $("#routeType").attr("value",'');
                     $("#proStyleNo").attr("value",'');
                     $("#commnet").attr("value",'');
                     window.location.reload();
                 });
               }
             }
     function update(Id){
              var routeType = $.trim($("#RouteType"+Id).val());
              var styleNo = $.trim($("#ProStyleNo"+Id).val());
              var comment = $.trim($("#Comment"+Id).val());
              if(routeType==""||styleNo==""){
                 alert("路由设置或款号不能为空!");
                 return;
               }else{
                 routeService.updateWdByExample({wdId:Id,routeType:routeType,proStyleNo:styleNo,comment:comment},function(){
                     alert("修改成功!");
                     window.location.reload();
                 });
               }
            };
      
      var errorHandle = function(err){
          alert(err);
      };
      dwr.engine.setErrorHandler(errorHandle); 

      var formSubmit = function (curPage){
        $("#curPage").val(curPage);
        document.settingForm.submit();
      }
      PaginatedTools.setCallBackFun(formSubmit);
    </script>
  </body>
</html>
